package top.asteam.springcloud.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import top.asteam.springcloud.service.PaymentService;

/**
 * @Author Rock Wang
 * @Time 2021/4/20
 */
@Slf4j
@RestController
@RequestMapping("/payment/hystrix")
public class PaymentController {

    @Autowired
    private PaymentService paymentService;

    @Value("${server.port}")
    private String serverPort;

    @GetMapping("/ok")
    public String paymentInfoOk(@RequestParam Long id) {
        String s = paymentService.paymentInfoOk(id);
        log.info(s);
        return s;

    }

    @GetMapping("/error")
    public String paymentInfoTimeOut(@RequestParam Long id) {
        String s = paymentService.paymentInfoTimeOut(id);
        log.info(s);
        return s;
    }

    //====服务熔断

    @GetMapping("/circuit")
    public String paymentCircuitBreaker(@RequestParam Long id)
    {
        String result = paymentService.paymentCircuitBreaker(id);
        log.info("****result: "+result);
        return result;
    }


}
